#!/bin/bash

source ./nacos.env
echo '正在初始化环境'
# 设置家目录
home=$ALBERTMU_NACOS_WORKSPACE
if [[ -d $home ]]; then
    echo "初始化环境失败，文件夹【${home}】已存在。"
    exit 1
fi
# 创建家文件夹、配置文件夹和数据文件夹
mkdir $home && mkdir $home/logs
echo '初始化成功'
echo '正在部署容器'
docker run -d --name $ALBERTMU_C_NAME \
 -p 8848:8848 -p 9848:9848 \
 --restart=always \
 --privileged=true \
 --net $VNET_NAME \
 -e "PREFER_HOST_MODE=my-nacos" \
 -e "MODE=standalone" \
 -e "MYSQL_SERVICE_HOST=my_nacos" \
 -e "MYSQL_SERVICE_DB_NAME=nacos_dev" \
 -e "MYSQL_SERVICE_PORT=3306" \
 -e "MYSQL_SERVICE_USER=root" \
 -e "MYSQL_SERVICE_PASSWORD=1234567890" \
 -e "MYSQL_SERVICE_DB_PARAM=characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true" \
 -e "NACOS_AUTH_IDENTITY_KEY=2222" \
 -e "NACOS_AUTH_IDENTITY_VALUE=2xxx" \
 -e "NACOS_AUTH_TOKEN=SecretKey012345678901234567890123456789012345678901234567890123456789" \
 -e "SPRING_DATASOURCE_PLATFORM=mysql" \
 -v ${home}/logs:/home/nacos/logs \
 nacos/nacos-server:$ALBERTMU_NACOS_VERSION
echo 'nacos部署成功！'
